﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using Microsoft.SilverlightMediaFramework.Core;
using Microsoft.SilverlightMediaFramework.Plugins.Primitives;

namespace Ausy.Silverlight.VideoPlayer.MediaModule.Extensions.Converters
{
    /// <summary>
    /// Cette classe représente un convertisseur d'une Uri d'une vidéo en PlayList contenant 1 item 
    /// </summary>
    public class PlayStateConverter : IValueConverter
    {
        /// <summary>
        /// Cettte méthode permet de convertir une Uri en PlayList
        /// </summary>
        /// <param name="value">Uri</param>
        /// <param name="targetType">PlayList</param>
        /// <param name="parameter">Empty</param>
        /// <param name="culture">Empty</param>
        /// <returns>PlayList</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool playing = System.Convert.ToBoolean(value);
            if (playing)
            {
                return MediaPluginState.Playing;
            }
            else
            {
                return MediaPluginState.Paused;
            }
        }

        /// <summary>
        /// Méthode non implémenté
        /// </summary>
        /// <param name="value">PlayList</param>
        /// <param name="targetType">ObservableCollectionPlaylistItem</param>
        /// <param name="parameter">Empty</param>
        /// <param name="culture">Empty</param>
        /// <returns>Uri</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var result = false;
            MediaPluginState state = (MediaPluginState) Enum.Parse(typeof(MediaPluginState),System.Convert.ToString(value), true) ;
            switch (state)
            {
                //case MediaPluginState.AcquiringLicense:
                //    result = false;
                //    break;
                //case MediaPluginState.Buffering:
                //    result = false;
                //    break;
                //case MediaPluginState.ClipPlaying:
                //    result = false;
                //    break;
                //case MediaPluginState.Closed:
                //    result = false;
                //    break;
                //case MediaPluginState.Individualizing:
                //    result = false;
                //    result = false;
                //    break;
                //case MediaPluginState.Opening:
                //    result = false;
                //    break;
                //case MediaPluginState.Paused:
                //    result = false;
                //    break;
                case MediaPluginState.Playing:
                    result = true;
                    break;
                case MediaPluginState.Stopped:
                    result = false;
                    break;
                //default:
                //    result = false;
                //    break;
            }

            return result;
        }
    }
}
